﻿@model CloudStorageLight.Core.Web.FileTransferWorkTaskVM

@{
    ViewBag.Title = "File Transfer";
    Layout = "~/Views/Shared/_LayoutCloudStorage.cshtml";
}

<header class="nrm nlm">

    <div class="clearfix" id="header-cont">
        <div class="place-right">
            <div class="margin10">
                <i class="icon-user" style="font-size:medium;"></i>
                @(Model.User.OperatorName ?? Model.User.Name.Split('@')[0])
                <a id="home" href="@Url.Action("Index", "Home", new { id="/" })"><i class="icon-exit" title="home" style="background:white;color:blue;padding:10px;border-radius:50%"></i></a>
            </div>
        </div>
        <div class="place-left margin10">
            <nav class="horizontal-menu">
                <ul>
                    @Html.Partial("_HomeCommand")
                    <li><a id="download-command" href="javascript:void(0);" class="header-command">@(CloudStorageLight.Core.Web.ViewMessages.CmdDownload)</a></li>
                    @if (!string.IsNullOrEmpty(Model.WorkTask.FileReciveMode) && Model.WorkTask.FileReciveMode != CloudStorageLight.Core.FileReciveMode.None.ToString())
                    {
                        <li><a id="upload-command" href="javascript:void(0);" class="header-command">@(CloudStorageLight.Core.Web.ViewMessages.CmdUpload)</a></li>
                    }
                    <li>
                        <a class="dropdown-toggle header-command" id="operation-command" href="#" >@(CloudStorageLight.Core.Web.ViewMessages.CmdOperation)</a>
                        <ul class="dropdown-menu" data-role="dropdown">
                            <li><a id="selectall-command"  href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdSelectAll)</a></li>
                            <li><a id="unselectall-command" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdUnSelectAll)</a></li>
                        </ul>
                    </li>
                </ul>
            </nav>
        </div>
    </div>
</header>
<div class="notify-message" style="margin-bottom:50px;">
</div>
<div id="folder-cont" class="listview-outlook">
    <div id="file-items">
        <h4>@(CloudStorageLight.Core.Web.ViewMessages.MsgDownloadableFiles)</h4>
        @{int idx=0;}
        @foreach (CloudStorageLight.Core.Web.FileItem file in Model.DownloadableFiles)
        {
            <div class="list">
                <div class="list-content">
                    <a href="@(Request.Url.AbsolutePath.TrimEnd('/') + "/" + file.Title + "?fileNo=" + idx.ToString() )">
                        <i class="icon-download icon"></i>
                    </a>
                    <div class="blobfile data" data-href="@(Request.Url.AbsolutePath.TrimEnd('/') + "/" + file.Title +  "?fileNo=" + idx.ToString())">
                        <span class="list-title">
                            <label>
                                <input type="checkbox" class="item-checkbox" name="@(file.Path)" />
                                <span class="item-name">@(file.Title)</span>
                            </label>
                        </span>
                        <div class="list-subtitle">
                            <span>@(file.LastModified.HasValue ? file.LastModified.Value.ToLocalTime().ToString("F") : "")</span>
                            <span>@(CloudStorageLight.Core.Web.WebUtil.SizeSuffix(file.Length))</span>
                        </div>
                    </div>
                    <span class="list-remark fg-darkRed">
                    </span>
                </div>
            </div>
            idx++;
        }


        @if (Model.UploadedFiles.Count > 0)
        {
            <h4 style="margin-top:50px;">@(CloudStorageLight.Core.Web.ViewMessages.MsgUploadedFiles)</h4>
            foreach (CloudStorageLight.Core.Web.FileItem file in Model.UploadedFiles)
            {

                <div class="list">
                    <div class="list-content">
                        <i class="icon-file icon"></i>
                        <div class="blobfile data">
                            <span class="list-title">
                                <span class="item-name">@(file.Title)</span>
                            </span>
                            <div class="list-subtitle">
                                <span>@(file.LastModified.HasValue ? file.LastModified.Value.ToLocalTime().ToString("F") : "")</span>
                                <span>@(CloudStorageLight.Core.Web.WebUtil.SizeSuffix(file.Length))</span>
                            </div>
                        </div>
                    </div>
                </div>
            }
        }



    </div>
</div>
<div id="download-confirm-dialog" style="display:none;">
    <p>@(CloudStorageLight.Core.Web.ViewMessages.MsgConfirmDownloadZip)</p>
    <div>
        <button id="download-zip-file-transfer-command" class="button" type="button">YES</button>
        <button id="download-files-command" class="button" type="button">NO</button>
    </div>
</div>
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "upload", enctype = "multipart/form-data" }))
{
    if (!this.Request.Browser.IsMobileDevice)
    {
        <input type="file" id="upl" name="upl" style="display:none;" multiple />
    }
    else
    {
        <input type="file" id="upl" name="upl" style="display:none;" />
    }
}

<div id="file-drop-cont" style="display:none;">
    <span>
        @(CloudStorageLight.Core.Web.ViewMessages.MsgPleaseDropHere)
    </span>
</div>
@section scripts{
    <script type="text/javascript">
        @Html.Partial("_Message")
        $('#download-zip-file-transfer-command').click(function () {
            CloudStorageLight.StorageController.downloadZip('@(Url.Action("DownloadAsZip", "WorkTask", new { id=Model.Id }))');
            $("#download-confirm-dialog").dialog("close");
        });

        var dragHelp = false;

        $(document).bind("dragenter", function (evt) {
            var oev = evt.originalEvent;
            if (!oev.dataTransfer.types || oev.dataTransfer.types.length == 0 || oev.dataTransfer.types[0] != "Files") return;
            evt.stopPropagation();
            evt.preventDefault();
            if (dragHelp) return;
            dragHelp = true;
            $('#file-drop-cont').show();
        });

        $("#file-drop-cont").bind("dragleave", function (evt) {
            evt.stopPropagation();
            evt.preventDefault();
            if (!dragHelp) return;
            dragHelp = false;
            $('#file-drop-cont').hide();
        });

        $("#file-drop-cont").click(function () {
            dragHelp = false;
            $('#file-drop-cont').hide();
        });

        $('#upload').fileupload({
            dropZone: $('#file-drop-cont'),
            singleFileUploads: true,
            add: function (e, data) {
                CloudStorageLight.StorageController.upload(data);
                dragHelp = false;
                $('#file-drop-cont').hide();
            },
            done: function (e, data) {
            }
        });

    </script>

}
